
	mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					up: {
						auto:false,
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
	});
	
	
	var userinfo = app.getState() || {};
    var uid = userinfo.user_id;
    var currenPage=1;
    var pageSize=10;
    var total_page=0;
    var total_count=0;
    
    window.onload = function(){
    	mui.ajax({
				url: apiurl + "User/share_record/",
				data: {'user_id':uid,'p':currenPage,'size':pageSize,'_token':userinfo.token},
				async: true,
				dataType: 'json',
				crossDomain: true, //强制使用5+跨域
				type: 'get',
				timeout: 10000,
				success: function(res) {
					console.log(JSON.stringify(res));
					// 请求成功
					if(res.status ==-3){
						mui.toast(res.msg);
						app.out();
						return false;
					} else {
						total_page=res.total_page;
						total_count=res.sum;
						var htm=get_data(res.resource);
						$('#pullrefresh .mui-scroll ul').append(htm);
					}
				},
				error: function(xhr, type, errorThrown) {
					//console.log(JSON.stringify(xhr));
					//console.log(JSON.stringify(type));
					//console.log(JSON.stringify(errorThrown));
					mui.toast('获取数据失败！');
				}
			});
			
			 mui.plusReady(function(){
			    //关闭等待框
			    plus.nativeUI.closeWaiting();
			    //显示当前页面
			    mui.currentWebview.show();
			});

    }

    function get_data(data){
    	var htm='';
		for(i in data) {
			/*
			 * <li class="mui-table-view-cell">
						<div>
							<img class="mui-media-object mui-pull-left" src="../../img/logo.png">
							<div class="mui-media-body">
								<p>HEART(UID:311136)</p>
								<div class="credit">手机号：15266668888</div>
								<div class="credit">分享时间：2018-05-14</div>
							</div>
						</div>
					</li>
			 */
			htm += '<li class="mui-table-view-cell">';
			htm+='<div>';
			if(data[i]['has_headimg']==1){
				//var imgpath=serverurl + 'Uploads/avatar/' + data[i]['user_id'] + '.jpg';
				if(data[i]['headimgurl'].indexOf(upurl+'Uploads') !== -1){
					var imgpath=data[i]['headimgurl'];
				}
				else{
					var imgpath=upurl+data[i]['headimgurl'];
				}
			}else{
				var imgpath='../../img/logo.png';
			}
			htm+='<img class="mui-media-object mui-pull-left" src="'+imgpath+'">';
			htm+='<div class="mui-media-body">';
			htm+='<p>'+data[i]['nickname']+'(UID:'+data[i]['user_id']+')</p>';
			htm+='<div class="credit">手机号：'+data[i]['mobile']+'</div>';
			htm+='<div class="credit">分享时间：'+data[i]['reg_time']+'</div>';
			htm+='</div>';
			htm+='</div>';
			htm+='</li>';
		}
		return htm;
    }


	function pullupRefresh() {
		setTimeout(function() {
			currenPage++;
			mui.ajax({
				url: apiurl + "User/share_record/",
				data: {'user_id':uid,'p':currenPage,'size':pageSize,'_token':userinfo.token},
				async: true,
				dataType: 'json',
				crossDomain: true, //强制使用5+跨域
				type: 'get',
				timeout: 10000,
				success: function(res) {
					console.log(JSON.stringify(res));
					// 请求成功
					if(res.status ==-3){
						mui.toast(res.msg);
						app.out();
						return false;
					} else {
						var htm=get_data(res.resource);
						$('#pullrefresh .mui-scroll ul').append(htm);
					}
					
					if(currenPage < total_page){
	                    mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);    /*能上拉*/
	                }else{
	                    mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);/*不能上拉*/
	                }
				},
				error: function(xhr, type, errorThrown) {
					//console.log(JSON.stringify(xhr));
					//console.log(JSON.stringify(type));
					//console.log(JSON.stringify(errorThrown));
					mui.toast('获取数据失败！');
				}
			});
			
		}, 1500);
	}
	
